﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Web;
using Localization;
using SinBiota.Model.Entities;

namespace Sinbiota.Web.Authentication
{
    public class SendMail
    {
        //Send Email Method
        public static void SendResetEmail(User user, string resetKey,  string resetLink)
        {
            SendEmail(user.Email, String.Format("<p>" + Messages.ResetPassword + "</p>", string.Format("{0} ({1})", user.Name, user.Username), resetLink));
        }
        public static void SendNewUserEmail(User user, string resetKey,  string resetLink, string homeUrl, string loginUrl)
        {
            SendEmail(user.Email, String.Format("<p>" + Messages.NewUserEmail + "</p>", user.Name, homeUrl, user.Username, resetLink, loginUrl));
        }

        public static void SendMultipleEmailsResetWarning(string emailAddress)
        {
            SendEmail(emailAddress, String.Format("<p>" + Messages.MultipleEmailsResetWarning + "</p>"));
        }
        private static void SendEmail(string emailAddress, string message)
        {

            var email = new MailMessage { From = new MailAddress(ConfigurationManager.AppSettings["TechSupportEmail"]) };

            email.To.Add(new MailAddress(emailAddress));

            email.Subject = string.Format("Sinbiota - {0}", Strings.ResetPassword);
            email.IsBodyHtml = true;
            email.Body = message;

            var smtpClient = new SmtpClient();

            smtpClient.Send(email);
        }



    }
}